package gui.crud;

import gui.util.NumberOnlyListener;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import persistence.ProfessorHandler;

public class ProfessorEditPanel extends AbstractEditPanel {
	
	private ProfessorHandler p;

	private JTextField pNameField, pRegistrationField;
	private JLabel pNameLabel, pRegistrationLabel;
	
	public ProfessorEditPanel() {
		super("Administrar Professores", 400, 360);
	}

	

	@Override
	protected void setUpNewComponents() {
		pNameField = new JTextField();
		pRegistrationField = new JTextField();
		pNameLabel = new JLabel("<html><i><b>Nome:</b></i></html>");
		pRegistrationLabel = new JLabel("<html><i><b>Matricula:</b></i></html>");
		
		pNameField.setBounds(60, 130, 120, 20);
		pRegistrationField.setBounds(200, 130, 90, 20);
		pNameLabel.setBounds(60, 108, 120, 20);
		pRegistrationLabel.setBounds(200, 108, 120, 20);
		
		pRegistrationField.addKeyListener(new NumberOnlyListener());
	}

	@Override
	protected void addNewComponents() {
		this.add(pNameField);
		this.add(pRegistrationField);
		this.add(pNameLabel);
		this.add(pRegistrationLabel);
	}
	
	@Override
	protected void confirmChanges() {
		p.update(pNameField.getText(), pRegistrationField.getText());
	}

	@Override
	protected void deleteAction() {
		p.delete(pRegistrationField.getText());
	}

	@Override
	protected void setObjectsTypeAndContent() {
		getObjectsLabel().setText("<html><i><b>Professores:</b></i></html>");
		try {
		//	 p = new ProfessorHandler();
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Erro", JOptionPane.ERROR_MESSAGE);
			return;
		}
	}



	@Override
	protected void updateFields() {
		// TODO Auto-generated method stub
		
	}

}
